﻿using MediatR;
using T_Material.API.Application.Commands.StatisticsCommand;
using T_Material.Domain;
using T_Material.Infrastructure.Interface;

namespace T_Material.API.Application.CommandHandlers.StatisticsHandlers
{
    public class StatisticsUpdateCommandHandler : IRequestHandler<StatisticsUpdateCommand, int>
    {
        private readonly IStatisticsRepository statisticsRepository;
        public StatisticsUpdateCommandHandler(IStatisticsRepository statisticsRepository)
        {
            this.statisticsRepository = statisticsRepository;
        }
        public async Task<int> Handle(StatisticsUpdateCommand request, CancellationToken cancellationToken)
        {
            var info = new Statistics();
            info.Id = request.Id;
            info.GoodsName = request.GoodsName;
            info.TypeName = request.TypeName;
            info.Specifications = request.Specifications;
            info.Country = request.Country;
            info.Province = request.Province;
            info.PurchaseCount = request.PurchaseCount;
            info.ReceivedCount = request.ReceivedCount;
            info.SurplusCount = request.SurplusCount;
            info.MaterialQuality = request.MaterialQuality;
            info.UpdateBy = "李四";
            info.UpdateDate = DateTime.Now;
            info.IsDel = false;
            var res = await statisticsRepository.Update(info);
            return res;
        }
    }
}
